package com.cpe.web.config;

import java.util.List;
import java.util.Map;

import org.springframework.web.servlet.HandlerInterceptor;

import com.google.common.collect.Maps;
import com.cpe.web.intercepter.base.InterceptorConfigurer;
import com.cpe.web.intercepter.global.pre.ReqHeaderInterceptor;
import com.cpe.web.intercepter.separate.wechat.Login4WechatInterceptor;

/**
 * 注册全局拦截器和分流拦截器
 * 
 * @description TODO
 * @author zhoud
 * @date 2015年11月10日 下午5:45:56
 */
public class InterceptorConfig extends InterceptorConfigurer {
	/*---------------------------全局拦截器---------------------------*/
	/**
	 * 注册前置拦截器链
	 */
	@Override
	public HandlerInterceptor[] getPreInterceptors() {
		// 1.请求头拦截器
		ReqHeaderInterceptor reqHeaderInterceptor = new ReqHeaderInterceptor();
		return new HandlerInterceptor[] { reqHeaderInterceptor };
	}

	/**
	 * 注册后置拦截器链
	 */
	@Override
	protected HandlerInterceptor[] getPostInterceptors() {
		return new HandlerInterceptor[] {};
	}

	/*---------------------------分流拦截器---------------------------*/
	/**
	 * 注册CMS拦截器链
	 */
	@Override
	public HandlerInterceptor[] getCMSInterceptors() {
		return new HandlerInterceptor[] {};
	}

	/**
	 * 注册移动端拦截器链
	 */
	@Override
	public HandlerInterceptor[] getMobileInterceptors() {
		return new HandlerInterceptor[] {};
	}

	/**
	 * 注册PC端拦截器链
	 */
	@Override
	protected HandlerInterceptor[] getPCInterceptors() {
		return new HandlerInterceptor[] {};
	}

	@Override
	protected HandlerInterceptor[] getWechatInterceptors() {
		Login4WechatInterceptor login4WechatInterceptor = new Login4WechatInterceptor();
		login4WechatInterceptor.addExclusion("/wechat/messages");
		login4WechatInterceptor.addExclusion("/wechat/login");
		return new HandlerInterceptor[] {};
	}

	/**
	 * 注册自定义拦截器链
	 */
	@Override
	protected Map<String, List<HandlerInterceptor>> getCustomInterceptors() {
		Map<String, List<HandlerInterceptor>> map = Maps.newHashMap();

		return map;
	}

	private static InterceptorConfig instance = new InterceptorConfig();

	private InterceptorConfig() {
	}

	public static InterceptorConfig instance() {
		return instance;
	}
}
